<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class StockData extends Model
{
    protected $table = 'stock_data';

    function getStockMonthDown($startdate,$enddate,$percent){
       $data =  $this->select('code',DB::raw('SUM(p_change) as percent'))
                    ->where([
                        ['date','<',$enddate],
                        ['date','>',$startdate],
                    ])
                    ->groupBy('code')
                    ->havingRaw('SUM(p_change) < '.$percent )
                    ->orderBy('percent')
                    ->limit(100)
                    ->get();
       return $data;
        // $this->limit(30)->groupBy('codess')->get();
    }

}
